Species distribution modeling

Species distribution
code
analysis
Author

Hafez Ahmad

Published

October 16, 2022

You will find basic R codes

wildtype<- c(103,1125,504,608,794,698,920,535,842,765,945,1005,724,498,727)
print(wildtype)
 [1]  103 1125  504  608  794  698  920  535  842  765  945 1005  724  498  727

#2. Create variable called “resistant”—-

resistant<- c(768, 230, 854 ,637,426, 482, 1118, 524, 604 ,730 ,17 ,421, 587, 782 ,171)
print(resistant)
 [1]  768  230  854  637  426  482 1118  524  604  730   17  421  587  782  171

#3. combine the the vectors into data frame called “miner”—-

miner<- data.frame("wild"=wildtype,"resist"=resistant)
print(miner)
   wild resist
1   103    768
2  1125    230
3   504    854
4   608    637
5   794    426
6   698    482
7   920   1118
8   535    524
9   842    604
10  765    730
11  945     17
12 1005    421
13  724    587
14  498    782
15  727    171

#4. Calculate the mean and variance of the wildtype and resistant from the data frame “miner”—-

print(paste0("The mean of wildtype is ",round(x=mean(miner$wild),digits=3)," and the variance is ",round(x=var(miner$wild),digits=3)))
[1] "The mean of wildtype is 719.533 and the variance is 63014.552"
print(paste0("The mean of resistant is ",round(x=mean(miner$resist),digits=3)," and the variance is ",round(x=var(miner$resist),digits=3)))
[1] "The mean of resistant is 556.733 and the variance is 80529.21"

5. write a function for standard error called “stderror”—-

formula for standard error is standard deviation/square root ($ {(n)}$) of sample size

stderror<- function(x,n=length(x)){
  return(sd(x)/sqrt(n))
}

#…apply the function to the data frame “miner”—-

print(paste0("The standard error of wildtype is ",round(x=stderror(miner$wild),digits=3)))
[1] "The standard error of wildtype is 64.815"
print(paste0("The standard error of resistant is ",round(x=stderror(miner$resist),digits=3)))
[1] "The standard error of resistant is 73.271"

#6. write a function for growth rate called “rate” —-

where, nt is the vector abunace at t,ntplus the vector of abunance at year t+1 and t for vector of years and return plot for growth rate … load data from laptop